<div class="popup" style="width:530px;">
    <h3 class="title"><span>Tải ảnh từ máy tính</span></h3>
    <div class="popup_content">
        <form method="post" action="/deals/upload.html" enctype="multipart/form-data">
        <div class="choosse_file">
            <span class="txt">Choose Image</span>
            <input type="file" id="images" name="images[]" multiple />
            <p class="path_file"><input type="text" placeholder="Tải tối đa 4 ảnh"/></p>
        </div>
        <div class="list_images"></div>
        <!--<div class="list_images">
            <img src="images/img_up_115x68.jpg" />
            <img src="images/img_up_115x68.jpg" />
            <img src="images/img_up_115x68.jpg" />
            <img src="images/img_up_115x68.jpg" />
        </div>-->
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Tên deal:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <input type="text" name="title" required />
                </span>
            </label>
        </div>
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Lĩnh vực:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <div class="zone seleComm">
                    	<div class="listitem">
                            <a href="javascript:;">-- Vui lòng chọn --</a>
                        </div>
                        <select class="selZone required" name="category[]" required>
                        	<option>-- Vui lòng chọn --</option>
                           	<?php foreach(Yii::app()->session['arrDeals'] as $R): ?>
                            <option <?php if($R['category_code'] == Yii::app()->request->getParam('loc', null)):?>selected<?php endif;?> value="<?php echo $R['category_id']; ?>">
                                <?php for($i=0; $i<$R['category_level']; $i++): echo '&nbsp;&nbsp;&nbsp;'; endfor; ?>
                                <?php echo $R['category_name']; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                        <span class="ico_all ico_arr_zone"><em></em></span>
                    </div>
                </span>
            </label>
        </div> 
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Địa điểm:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <div class="zone seleComm">  
                    	<div class="listitem">
                            <a href="javascript:;">-- Vui lòng chọn --</a>
                        </div>                      
                        <select class="selZone required" name="category[]" required>
                        	<option>-- Vui lòng chọn --</option>
                           	<?php foreach(Yii::app()->session['arrLocations'] as $R): ?>
                            <option <?php if($R['category_code'] == Yii::app()->request->getParam('loc', null)):?>selected<?php endif;?> value="<?php echo $R['category_id']; ?>">
                                <?php for($i=0; $i<$R['category_level']; $i++): echo '&nbsp;&nbsp;&nbsp;'; endfor; ?>
                                <?php echo $R['category_name']; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                        <span class="ico_all ico_arr_zone"><em></em></span>
                    </div>
                </span>
            </label>
        </div>  
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Địa chỉ:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <input type="text" name="fields[1]" required />
                </span>
            </label>
        </div>
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Số điện thoại:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <input type="text" name="fields[2]" />
                </span>
            </label>
        </div>
        <!--
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Loại deal:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <select class="selZone required" name="loaideal" required>
                        <option>-- Vui lòng chọn --</option>
                        <option> Giảm giá </option>
                        <option> Khuyến mãi </option>
                    </select>
                </span>
            </label>
        </div>-->
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Tiết kiệm (%):</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <input type="text" name="fields[3]" required />
                </span>
            </label>
        </div>
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Thời gian hết hạn:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <input type="text" name="expiry" id="expiry" readonly />
                </span>
            </label>
        </div>
        <div class="each_row">
            <label class="lbl_txt">
                <span class="col-md-3 col-sm-3 col-xs-12">Thông tin khác:</span>
                <span class="col-md-9 col-sm-9 col-xs-12">
                    <textarea rows="7" name="body"></textarea>
                </span>
            </label>
        </div>
        <div class="each_row">
            <!--<label class="lbl_txt">
                <span>Chia sẻ:</span>
                <img src="images/icon_face_70x21.jpg" />
                <input type="checkbox" />
            </label>-->
            <input class="btn_blueWhite" type="submit" value="Upload deal" />
        </div>
        </form>
    </div>
</div>
<script>
$(document).ready(function(e) {
	$("#expiry").datepicker({
		dateFormat:'dd/mm/yy',
		maxDate: '0'		
	});
	$('.seleComm select').change(function(){
		var strVal = "";
		$(this).find('option:selected').each(function(){
			strVal = $(this).text();	
		});
		$(this).parent('.seleComm').find('.listitem a').html(strVal);
	});
	
	// set up variables
	var reader = new FileReader(),
		i=0,
		numFiles = 0,
		imageFiles;
	
	// use the FileReader to read image i
	function readFile() {
		reader.readAsDataURL(imageFiles[i])
	}
	
	// define function to be run when the File
	// reader has finished reading the file
	reader.onloadend = function(e) {
	
		// make an image and append it to the div
		var image = $('<img width="115px" height="68px">').attr('src', e.target.result);
		$(image).appendTo('.list_images');
		
		//var input = $('<input type="radio" name="avatar" value="1">').appendTo('.list_images');
	
		// if there are more files run the file reader again
		if (i < numFiles) {
			i++;
			readFile();
		}
	};
	
	$('#images').change(function() {
		imageFiles = document.getElementById('images').files;
		// get the number of files
		numFiles = imageFiles.length;
		readFile();           
	});
});
</script>
